document.addEventListener('DOMContentLoaded', function() {
    const slides = document.querySelector('.slides');
    const images = document.querySelectorAll('.slides img');
    let index = 0; // 当前显示的图片索引

    function showSlide(index) {
        slides.style.transform = `translateX(-${index * 100}%)`; // 移动到对应的图片位置
    }

    function nextSlide() {
        // 显示下一张图片
        index = (index + 1) % images.length;
        showSlide(index);
    }

    // 设置定时器，每3秒切换到下一张图片
    let intervalId = setInterval(nextSlide, 3000);

    // 设置一个定时器，在显示每张图片2秒后切换到下一张
    let displayDuration = 2000; // 显示每张图片的持续时间（毫秒）
    let timeoutId = setTimeout(nextSlide, displayDuration);

    // 每张图片停留两秒后切换
    function resetTimer() {
        clearTimeout(timeoutId);
        timeoutId = setTimeout(nextSlide, displayDuration);
    }

    // 重置定时器，每张图片停留两秒
    intervalId = setInterval(resetTimer, 3000);
});

document.addEventListener('DOMContentLoaded', function() {
    const quizForm = document.getElementById('quizForm');
    const questions = [
        // 这里添加10个问题和选项
        { question: "辛亥革命爆发于哪一年", answer: "1911年" },
        { question: "辛亥革命推翻的王朝是", answer: "清朝" },
        { question: "谁被推选为中华民国临时大总统", answer: "孙中山" },
        { question: "标志辛亥革命爆发的起义是", answer: "武昌起义" },
        { question: "中华民国临时政府成立的地点是在", answer: "南京" },    
        { question: "中华民国临时政府成立的地点是在", answer: "孙中山" },  

        // 更多问题...
    ];

    function loadQuestions() {
        const questionsContainer = document.getElementById('questions');
        questions.forEach((question, index) => {
            const questionElement = document.createElement('div');
            questionElement.innerHTML = `<h3>${question.question}</h3>
                <input type="text" id="answer${index}" name="answer${index}" required>
                <br>`;
            questionsContainer.appendChild(questionElement);
        });
    }

    loadQuestions();

    quizForm.onsubmit = function(event) {
        event.preventDefault();
        let correctAnswers = 0;
        questions.forEach((question, index) => {
            const userAnswer = document.getElementById(`answer${index}`).value;
            if (userAnswer === question.answer) {
                correctAnswers++;
            }
        });

        if (correctAnswers === questions.length) {
            document.getElementById('result').innerHTML = '<span style="color: yellow;">回答正确，你太棒了！</span>';
        } else {
            const correctAnswersText = questions.map(q => `${q.question}：${q.answer}`).join('<br>');
            document.getElementById('result').innerHTML = `<span style="color: yellow;">很遗憾，回答错误。正确答案是：</span><br>${correctAnswersText}`
        }
    };
});
function toggleDetail(detailId) {
    const detail1 = document.getElementById(detailId);
    detail1.style.display = detail1.style.display === 'block' ? 'none' : 'block';
}
function toggleDetail(detailId) {
    const detail2 = document.getElementById(detailId);
    detail2.style.display = detail2.style.display === 'block' ? 'none' : 'block';
}
function toggleDetail(detailId) {
    const detail3 = document.getElementById(detailId);
    detail3.style.display = detail3.style.display === 'block' ? 'none' : 'block';
}
function toggleDetail(detailId) {
    const detail4 = document.getElementById(detailId);
    detail4.style.display = detail4.style.display === 'block' ? 'none' : 'block';
}
